package com.example.blogother.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.example.blogother.mapper.AdvertisingMapper;
import com.xpd.blog.bean.Advertising;
import com.xpd.blog.bean.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xpd
 * @since 2024-10-10
 */
@RestController
@RequestMapping("/advertising")
public class AdvertisingController {
    @Autowired
    AdvertisingMapper advertisingMapper;
    @RequestMapping("getAllPic")
    public Result getAllPic(@RequestParam int page,@RequestParam int size){
        Page p=new PageDTO(page,size);
        Page page1 = advertisingMapper.selectPage(p, null);
        return new Result(1,"查询成功",page1);
    }

    //添加
    @RequestMapping("addAdver")
    public Result addAdver(@RequestParam String pic){
        Advertising advertising=new Advertising();
        advertising.setPic(pic);
        advertising.setStatus(1);
        int insert = advertisingMapper.insert(advertising);
        if(insert>=1){
            return new Result(1,"上传成功",null);
        }else{
            return new Result(-1,"上传失败",null);
        }
    }
    //修改
    @RequestMapping("updateAder")
    public Result updateAder(@RequestBody Advertising advertising,@RequestParam int status){
        advertising.setStatus(status);
        LambdaQueryWrapper<Advertising> lqw=new LambdaQueryWrapper<>();
        lqw.eq(Advertising::getId,advertising.getId());
        int update =advertisingMapper.update(advertising,lqw);
        if(update>=1){
            return new Result(1,"修改成功",null);
        }else{
            return new Result(-1,"修改成功",null);
        }
    }
}

